package com.cssw.fyzb.web.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.web.dto.SaveLiveReportDto;
import com.cssw.fyzb.web.dto.UpdateFuncDto;
import com.cssw.fyzb.web.service.FuncService;
import com.cssw.fyzb.web.service.LiveReportService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ApiModel("举报管理")
@RestController
@RequestMapping("/liveReport")
public class LiveReportController {
    @Autowired
    LiveReportService liveReportService;

    @ApiOperation(value = "直播举报", response = AjaxPage.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "search", value = "搜索框", paramType = "query", dataType = "string", required = false),

    })
    public AjaxPage list(int page, int limit,String search) {
        Map param = new HashMap();
        param.put("search", search);
        return liveReportService.list(page, limit, param);
    }


    @ApiOperation(value = "下架直播视频", response = AjaxData.class)
    @PostMapping(value = "/update")
    @ApiImplicitParam(name = "dto", value = "下架直播", dataType = "SaveLiveReportDto")
    public AjaxData update(@RequestBody SaveLiveReportDto dto) {
        boolean result = liveReportService.update(dto.getReportId());
        if (result) return  AjaxData.success();
        else  return  AjaxData.failure();
    }

    @ApiOperation(value = "启用直播视频", response = AjaxData.class)
    @PostMapping(value = "/reject")
    @ApiImplicitParam(name = "dto", value = "下架直播", dataType = "SaveLiveReportDto")
    public AjaxData reject(@RequestBody SaveLiveReportDto dto) {
        boolean result = liveReportService.reject(dto.getReportId());
        if (result) return  AjaxData.success();
        else  return  AjaxData.failure();
    }
}
